<template>
	<view class="box">
		<view class="header"></view>
		<view class="content">
			<view class="uni-common-mt">
				<view class="login-title">欢迎登录动力源升级切换助手</view>
				<view class="uni-form-item">
					<view class="title"><text class="uni-form-item__title">用户名</text></view>
					<view class="uni-input-wrapper">
						<input v-model="form.username" class="uni-input-login" placeholder="请输入用户名" />
					</view>
				</view>
				<view class="uni-form-item">
					<view class="title"><text class="uni-form-item__title">密码</text></view>
					<view class="uni-input-wrapper">
						<input v-model="form.password" class="uni-input-login" type="password" placeholder="请输入密码" />
					</view>
				</view>
			</view>
			<view class="uni-btn">
				<button :loading="loginLoading" type="primary" @click="doLogin()">登录</button>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		login
	} from '@/api/api.js';
	export default {
		data() {
			return {
				form: {
					username: '',
					password: ''
				},
				loginLoading: false
			}
		},
		onLoad() {

		},
		methods: {
			// 登录
			doLogin() {
				if(!this.form.username){
					this.$Toast.none('请输入用户名');
					return;
				}
				else if(!this.form.password){
					this.$Toast.none('请输入密码');
					return;
				}
				this.$Toast.loading('登录中');
				login('', 'get', {
						password: this.form.password,
						username: this.form.username
					}).then(res => {
						if (res.code == 200) {
							this.$Toast.success('登录成功');
							uni.setStorageSync('token', res.data.token);
							uni.reLaunch({
								url: '/pages/index/index'
							});
						}
					})
					.catch(err => {

					})
			},
		}
	}
</script>

<style lang="scss" scoped>
	@import "@/static/css/common";

	.header {
		background-color: #1976D3;
		height: 100px;
	}

	.content {
		width: 80%;
		margin: 0px auto;
		background-color: #FFFFFF;
		border-radius: 10px;
		position: relative;
		bottom: 70px;
		padding: 20px 20px 30px 20px;
	}
	.login-title{
		font-size: 40rpx; 
		color: #378EE4;
		font-weight: 500;
		text-align: center;
		margin-bottom: 20rpx;
	}

	.title {
		padding: 5px 13px;
		width: 115rpx;
		text-align: right;
	}

	.uni-input-wrapper {
		width: 425rpx;
	}

	.uni-input-login {
		margin-top: 10rpx;
	}

	.uni-form-item {
		padding: 15px 0px;
		border-bottom: 1px solid #E6E6E6;
		@include flexLayout(center, flex-start);
	}

	.uni-btn {
		margin-top: 20px;
	}

	.uni-btn button {
		width: 100%;
		text-align: center;
		font-size: 32rpx;
		background-color: #4DA7FF;
		margin-top: 60rpx;
	}
</style>
